package com.yyq.adms.yyb.advance.action;


import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.yyq.adms.yyb.advance.bpo.STPaperBpo;
import com.yyq.adms.yyb.advance.pojo.STPaper;
import com.yyq.sos.action.BaseAction;
import com.yyq.sos.constants.ActionType;
import com.yyq.sos.constants.Constants;
import com.yyq.sos.permission.LoginUser;
import com.yyq.sos.util.PermissionsUtil;

/**
 * 科技进步 项目获奖Action
 * @author 杨应滨
 * @2012-12-8
 *
 */
@Controller("STPaperAction")
@Scope("prototype")
public class STPaperAction extends BaseAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	
	private STPaper po = new STPaper();
	
	private STPaperBpo bpo;

	public STPaper getPo() {
		return po;
	}

	public void setPo(STPaper po) {
		this.po = po;
	}

	public STPaperBpo getBpo() {
		return bpo;
	}

	@Resource(name="STPaperBpo")
	public void setBpo(STPaperBpo bpo) {
		bpo.setCls(po.getClass());
		this.bpo = bpo;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	
	
	public String execute()throws Exception
	{
		super.setBpo(bpo);
		super.setObj(po);
		String s = super.execute();
		this.setPo((STPaper)super.getObj());
		return s;
	}
	
	@Override
	public String data() {
		LoginUser user = (LoginUser)this.getSession().getAttribute(Constants.LOGIN_USER);
		String moduleName = getModuleName(this.getRequest().getRequestURI());
		boolean isPerm = PermissionsUtil.checkPermissionByCode(this.getSession(), moduleName,Constants.RIGHT_GLOBAL);
		String hql = "";
		if(user.getUserId().intValue()==1 || isPerm){
			hql = "from STPaper order by belongYear desc";
		}else{
			hql = "from "+po.getClass().getName()+" obj where obj.maintainDep="+user.getOrgId()+" or EXISTS(from RecordSentDep rsd where obj.id=rsd.sourceRecordId and rsd.yyqTableName='"+bpo.getTableName(po.getClass())+"' and rsd.sentDepId="+user.getOrgId()+")  order by obj.belongYear desc";
		}
		this.setFormData(bpo.searchPage(hql, getPageForm().getPageNo(), getPageForm().getPageSize()));
		return ActionType.ACTION_DATA_LIST;
	}

}
